# Define supported build platforms.
load("//bazel/platforms:remote_execution_containers.bzl", "REMOTE_EXECUTION_CONTAINERS")

package(default_visibility = ["//visibility:public"])

constraint_setting(name = "mongo_toolchain")

constraint_value(
    name = "use_mongo_toolchain",
    constraint_setting = ":mongo_toolchain",
)

constraint_setting(name = "distro")

[
    constraint_value(
        name = distro_or_os,
        constraint_setting = ":distro",
    )
    for distro_or_os in [
        "linux",
        "ubuntu18",
        "ubuntu20",
        "ubuntu22",
        "ubuntu24",
        "amazon_linux_2",
        "amazon_linux_2023",
        "debian10",
        "debian12",
        "rhel8",
        "rhel9",
        "suse12",
        "suse15",
    ]
]

[
    platform(
        name = distro_or_os + "_" + arch,
        constraint_values = [
            "@platforms//os:linux",
            "@platforms//cpu:arm64" if arch == "arm64" else "@platforms//cpu:x86_64",
            ":" + distro_or_os,
            ":use_mongo_toolchain",
        ],
        exec_properties = {
            "container-image": REMOTE_EXECUTION_CONTAINERS[distro_or_os]["container-url"],
            "dockerNetwork": "standard",

            # EngFlow's "default" pool is ARM64
            "Pool": "x86_64" if arch == "amd64" else "default",
        },
    )
    for arch in [
        "arm64",
        "amd64",
    ]
    for distro_or_os in [
        "linux",
        "ubuntu18",
        "ubuntu20",
        "ubuntu22",
        "ubuntu24",
        "amazon_linux_2",
        "amazon_linux_2023",
        "debian10",
        "debian12",
        "rhel8",
        "rhel9",
        "suse15",
    ]
]

platform(
    name = "windows_amd64",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:windows",
    ],
)

platform(
    name = "macos_arm64",
    constraint_values = [
        "@platforms//cpu:arm64",
        "@platforms//os:macos",
    ],
)

platform(
    name = "macos_amd64",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:macos",
    ],
)

platform(
    name = "linux_ppc64le",
    constraint_values = [
        "@platforms//cpu:ppc",
        "@platforms//os:linux",
    ],
)

platform(
    name = "linux_s390x",
    constraint_values = [
        "@platforms//cpu:s390x",
        "@platforms//os:linux",
    ],
)

platform(
    name = "rhel8_ppc64le",
    constraint_values = [
        "@platforms//cpu:ppc",
        "@platforms//os:linux",
        ":use_mongo_toolchain",
    ],
)

platform(
    name = "rhel8_s390x",
    constraint_values = [
        "@platforms//cpu:s390x",
        "@platforms//os:linux",
        ":use_mongo_toolchain",
    ],
)
